package com.gitee.cnlongs.cnlongmq.server.test;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.gitee.cnlongs.cnlongmq.basic.entitiy.request.CnLongMessageQueue;
import com.gitee.cnlongs.cnlongmq.basic.entitiy.response.CnLongMqResponse;
import com.gitee.cnlongs.cnlongmq.server.LongMqServer;

public class LongMqTest100 {
	
	public static void main(String[] args) {

		LongMqServer mqServer = new LongMqServer("configtest/longmqconfig0");
		
		while(true) {
//			System.out.println(mqServer.getExecuter().getLongMqConfig().getSequeueList().size() + "------" 
//					+ mqServer.getExecuter().getLongMqConfig().getCustomerSequeueList().size());
//			List<CnLongMessageQueue> customerSequeueList = mqServer.getExecuter().getLongMqConfig().getCustomerSequeueList();
//			for (CnLongMessageQueue queue : customerSequeueList) {
//				System.out.println("队列ip【"+queue.getLongMqIp()+
//						"】队列端口【"+queue.getLongMqPort()+"】队列状态【"+queue.getLongMqStatus()+"】");
//			}
			System.out.println("队长信息：" + mqServer.getExecuter().getLongMqConfig().getCaptainElectionSequeue()
					+ "；候补队长信息：" + mqServer.getExecuter().getLongMqConfig().getCaptainElectionMap().toString());
			try {
				Thread.sleep(3000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		
//		try {
//			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//			long time1 = System.currentTimeMillis();
//			String start = format.format(new Date());
//			
//			Map<String, String> params = new HashMap<String, String>();
//			params.put("one", "100");
//			params.put("two", "101");
//			params.put("three", "102");
//			CnLongMqResponse response = mqServer.sendLongMqMessage("cnlong-test101", params);
//			if(null != response && response.getReturnStatus()) {
//				System.out.println("mq发送时间：" + start + "; MQ消息发送操作总耗时：" + 
//						Float.toString((System.currentTimeMillis() - time1) / 1000F) + " 秒. ");
//				System.out.println(format.format(new Date()) + 
//						"; 发送mq消息，返回值是：" + JSON.toJSONString(response));
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
		
	}
	
}
